package com.my.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Session域对象
 *
 */
@WebServlet("/ser02")
public class Session02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取session对象
        HttpSession session = req.getSession();

        //设置域对象
        session.setAttribute("uname","admin");
        session.setAttribute("upwd","123456");
        //移除session对象
        session.removeAttribute("upwd");

        /**
         * request域对象
         */
        req.setAttribute("name","zhangsan");

        //请求转发
        req.getRequestDispatcher("index.jsp").forward(req,resp);


    }
}
